﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravelLib
{
    public class Journey
    {
        public Route ActualRoute
        {
            get;
            set;
        }
        public List<Flight> Flights
        {
            get;
            set;
        }

        public double GetTotalCost(int seats, TravelClassEnum travelclass)
        {
            double sum = 0;
            foreach (Flight f in Flights)
            {
                sum += f.GetTravelClassCost(travelclass) * (double)seats;
            }
            return sum;
        }

        public string ToString(int seats, TravelClassEnum travelclass)
        {
            string s = "ROUTE FROM " + ActualRoute.DepartureAirportName + " TO " + ActualRoute.DestinationAirtportName + Environment.NewLine +
                       "TOTAL COST: " + GetTotalCost(seats, travelclass);
            foreach (Flight f in Flights)
            {
                s += "FLIGHT " + f.Company.CompanyName + "|" + f.UID + " departs from " + f.Route.DepartureAirportName + "@" + f.DepartureTime.ToShortTimeString() + " destination " + f.Route.DestinationAirtportName + "@" + f.ArrivalTime.ToShortTimeString() + Environment.NewLine;
            }
            return s;
        }

        public bool IsEqual(Journey j)
        {
            if (!ActualRoute.IsEqual(j.ActualRoute))
                return false;
            if (j.Flights.Count != Flights.Count)
            {
                return false;
            }
            for (int i = 0; i < j.Flights.Count; ++i)
            {
                if (!Flights[i].IsEqual(j.Flights[i]))
                    return false;
            }
            return true;
        }


        public Journey()
        {

        }

        public bool IsNew { get; set; }
    }
}
